package com.flying.set;

import java.lang.reflect.AnnotatedArrayType;
import java.util.Comparator;
import java.util.Objects;

/**
 * @author liupengfei
 * @ClassName: Person
 * @Time: 2023-09-18 20:38
 * @Version: 1.0
 * @Descition
 */
public class Person implements Comparable<Person> {
    String name;
    int age;

    public Person(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public Person() {
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    // 自然排序
    @Override
    public int compareTo(Person o) {
        if (o == null){
            throw new RuntimeException("null");
        }

        if (this==o){
            return 0;
        }

        int age = o.getAge();
        // 从小到大  -
        return age!=this.age ? -Integer.compare(age, this.age):-o.getName().compareTo(this.getName());
    }
}
